from rest_framework import serializers
from apps.cms.models import News, NewsCategory
from apps.xfzauth.serializers import UserSerializer
from .models import Comment, Banner


# 新闻分类序列化
class NewsCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = NewsCategory
        fields = ('id', 'name')


# 新闻序列化
class NewsSerializer(serializers.ModelSerializer):
    category = NewsCategorySerializer()
    author = UserSerializer()

    class Meta:
        model = News
        fields = ('id', 'title', 'desc', 'thumbnail', 'pub_time', 'category', 'author')


# 新闻评论序列化
class CommentSerializer(serializers.ModelSerializer):
    author = UserSerializer()

    class Meta:
        model = Comment
        fields = ('id', 'content', 'author', 'pub_time')


# 轮播图序列化
class BannerSerializer(serializers.ModelSerializer):
    class Meta:
        model = Banner
        fields = ('id', 'priority', 'image_url', 'link_to')
